package com.fyy.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @Author fyy
 * @Description
 * @Date 2020/6/1 10:45
 */
@Configuration
public class BeanConfig {

    //配置RestTemplate为负载均衡Ribbon
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }


    /**
     * 更换轮询策略，ribbon默认使用轮询策略
     */
    @Bean
    public IRule myIRule(){
        return new RandomRule(); //随机
    }

}
